// rtgen_worker3.h

#pragma once

#using <mscorlib.dll>
#include <windows.h>
#include <time.h>

using namespace System;
using namespace System::Runtime::InteropServices;
using namespace System::Text;
using namespace System::Collections;
//#include "RainbowTableGenerator.h"
#include "HashRoutine.h"
#include "DictionaryCracker.h"
  
namespace rtgen_worker {
    public ref class RainbowCrackChain
    {
	public :
		System::UInt64 nStartingPoint;
		System::UInt32 nGuessedPos;
    };

	public delegate void UpdateCrackingProgressCallback(int RequestID, float fProgress);
	public delegate void PasswordCrackedCallback(String ^sHash, String ^sPassword);

	public ref class RainbowCrack
	{
	private:
//		CRainbowTableGenerator *pGenerator;	
		int nPassTried;
		int nProgress;
		CDictionaryCracker *m_pCracker;
		
		//inline int CheckPassword(unsigned char **ppHashList, int numHashes, unsigned char *md5, int nHashLen);
//		inline int checkPass(char *word, int wordlen, HASHROUTINE pHashFunction, PasswordCrackedCallback ^cbPassCracked);
	public:				
		Int32 GetPassTried() { return m_pCracker->GetPassTried(); }
		int GetProgress() { return nProgress; }
		RainbowCrack();
		~RainbowCrack();
		static PasswordCrackedCallback ^m_cbPassCracked;
		//Int32 rtgen_worker::RainbowCrack::GetKeyRate();
		static void ReportCracked(String ^sHash, String ^sPlain)
		{
			RainbowCrack::m_cbPassCracked(sHash, sPlain);
		}
		static int DoChainCheck(String ^Hash, String ^HashRoutine, String ^CharsetName, System::UInt32 PlainLenMin, System::UInt32 PlainLenMax, System::UInt32 RainbowTableIndex, System::UInt32 RainbowChainLen, System::Collections::Generic::Queue<RainbowCrackChain^> ^qChains, String ^Password);
		static int CalculateIndexList(array<UInt64> ^Indices, String ^Hash, String ^HashRoutineName, String ^PlainCharsetName, System::UInt32 GetPlainLenMin, System::UInt32 GetPlainLenMax, System::UInt32 RainbowTableIndex, System::UInt32 RainbowChainLen, System::UInt32 RequestID, UpdateCrackingProgressCallback ^cb);
		static int SortFile(String ^Filename);
//		int calculateTable(String ^fileName, String ^HashRoutineName, String ^CharsetName, System::Int32 nPlainLenMin, System::Int32 nPlainLenMax, System::Int32 nRainbowTableIndex, System::Int32 nRainbowChainLen, System::Int32 nRainbowChainCount, String ^Salt);
//		int GetSpeed();
//		int GetCurrentCalculatedChains();
		// TODO: Add your methods for this class here.
	};
}
